package com.ushine.web.security.handler;

import com.ushine.web.security.response.SecurityResponse;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: yls
 * @Date: 2021/08/17 22:24
 * @Description:
 * @Version 1.0
 */
@Component
public class FightExpiredSessionStrategy implements SessionInformationExpiredStrategy {

    @Resource
    SecurityResponse securityResponse;


    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        HttpServletResponse response = sessionInformationExpiredEvent.getResponse();
        securityResponse.getResponse(response, 500, "当前会话已失效，请重新登录！！！");
    }
}
